<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="p" uri="/pagination-tags"%>
<%@ taglib prefix="security" uri="/security-tags"%>
<%@ taglib prefix="hop" uri="/hoptree-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><s:property value="titleName"/>查询</title>
<script>
//此函数为ztree中callback函数，请确保该函数定义在hop:tree之前，一般定义在<head>的<script>中即可
function zTreeOnCheck(event, treeId, treeNode) {
	if(treeNode.checked == true){
		$("#parent_id").val(treeNode.id);
	}else{
		$("#parent_id").val('');
	}
}
</script>
</head>
<body> 
<div id="breadcrumbs">
	<div><div><ul>
		<li class="first"></li>
		<li><a href="#">商品数据</a></li>
		<li><a href="#">商品属性管理</a></li>
		<li class="last"><a href="#"><s:property value="titleName"/>查询</a></li>
	</ul></div></div>
</div>
<div class="section">
	<jsp:include page="/common/messages.jsp" />
	<div class="box">
		<div class="title">
			查询条件
			<span class="hide"></span>
		</div>
		<div class="content">
			<s:form action="searchGoodsCategory" namespace="/goods" method="get" id="searchForm">
				<table>
					<tr>
						<th>名称：</th>
						<th><s:textfield name="goodsCategory.name" /></th>
						<th>
							<button type="submit" class="orange" onclick="submitForm('searchGoodsCategory');"><span>查询</span></button>
							<button type="submit" class="blue" onclick="createForm()"><span>新建一级类目</span></button>
						</th>
					</tr>
				</table>
			</s:form>
		</div>
	</div>
</div>
<div class="section">
	<div class="box">
		<div class="title">
			查询结果
			<span class="hide"></span>
		</div>
		<div class="content">
			<div class="dataTables_wrapper">
				<div>
					<div class="dataTables_filter"></div>
				</div>
				 <div class="row">
						<label>分类:</label>
						<div class="right">
							<hop:tree url="${dynamicURL}/goods/displayCategoryTree.action?id=0"
									expandUrl="${dynamicURL}/goods/displayCategoryTree.action" 
									async="true" 
									chkType="radio" 
									id="depTree"
									setting="{check: {enable: true, chkStyle: 'radio', radioType: 'all'}, data: {simpleData: { enable: true}}, async: {enable:true, url: getTreeExpandUrl},callback:{onCheck: zTreeOnCheck} };"
									theme="default">
							</hop:tree>
			               	<s:hidden name="goodsCategory.parent.id" id="parent_id"/>
						</div>
				</div>	
				<div class="row">
					<button type="submit" class="green" onclick="updateForm()"><span>更新类目</span></button>
					<button type="submit" class="blue" onclick="createFormSub()"><span>新建子类目</span></button>					
				</div>		
			</div>
		</div>
	</div>
</div>

<script type="text/javascript">
//删除
function delForm(id){
	if (!confirm("确定要删除吗？")){
		return;
	}
	window.location.href = "${dynamicURL}/goods/deleteGoodsCategory.action?goodsCategory.id="+id;
}

function addForm(id){
	window.location.href = "${dynamicURL}/goods/addGoodsCategory.action?goodsCategory.parent.id="+id;
}

//删除
function updateForm(){
	document.getElementById('searchForm').onsubmit=function(){ return false; };
	var parentId = $("#parent_id").val();
	if(parentId==null || parentId==''){
		alert("请选择需更新类目");
		return ;
	}	
	window.location.href = "${dynamicURL}/goods/updateGoodsCategory.action?goodsCategory.id="+parentId;
}

function createForm(){
	document.getElementById('searchForm').onsubmit=function(){ return false; };
	
	window.location.href = "${dynamicURL}/goods/addGoodsCategory.action";
}

function createFormSub(){
	document.getElementById('searchForm').onsubmit=function(){ return false; };
	var parentId = $("#parent_id").val();
	if(parentId==null || parentId==''){
		alert("请选择父类目");
		return ;
	}
	window.location.href = "${dynamicURL}/goods/addGoodsCategory.action?goodsCategory.parent.id="+parentId;
}

function submitForm(action){
	var form = document.getElementById("searchForm");
	form.action="${dynamicURL}/goods/"+action+".action";
	form.submit();
}
</script>
</body>
</html>
